<?php

namespace app\admin\controller;

use app\common\controller\Admin;
use think\Request;
use app\common\model\Link as LinkModel;
use app\common\model\Type;

class Link extends Admin {

    public $linkModel;

    public function __construct(\think\Request $request = null) {
        parent::__construct($request);
        $this->linkModel = new LinkModel();
        $this->assign('linkType', config('link_type'));
        $this->assign('linkStatus', config('link_status'));
        $typeModel = new Type();
        $this->assign('linkGlass', $typeModel->getValueByPid(7));
    }

    /**
     * 显示资源列表
     *
     * @return \think\Response
     */
    public function index() {
        $list = $this->linkModel->order('list_order asc,siteid,typeid')->select();
        $this->assign('list', $list);
        return $this->fetch();
    }

    /**
     * 显示创建资源表单页.
     *
     * @return \think\Response
     */
    public function editlink() {
        $data = $this->request->param();
        if ($data['id']) {
            $this->linkModel->where('id', $data['id'])->update($data);
        } else {
            $this->linkModel->insert($data);
        }
        $this->success('操作成功');
    }

    /**
     * 更新排序
     */
    public function setOrder() {
        $param = $this->request->param();

        $this->_setorder($param['list_order'], 'link');

        $this->success('排序成功');
    }

    public function dellink($id) {
        $this->linkModel->where('id', $id)->delete();
        $this->success('删除成功');
    }

}
